/*
 * Confidential.  All Rights Reserved.
 * Copyright (C) 2011 Orangatame LLC.
 * Original Author: Jason Schroeder <jason@orangatame.com>
 * Created: Jun 7, 2011
 */
package com.google.authenticator.blackberry;

import java.util.Hashtable;

import net.rim.device.api.synchronization.SyncObject;
import net.rim.device.api.util.Persistable;

public class Account implements Persistable, SyncObject {

  static final String ID_COLUMN = "_id";
  static final String EMAIL_COLUMN = "email";
  static final String SECRET_COLUMN = "secret";
  static final String COUNTER_COLUMN = "counter";
  static final String TYPE_COLUMN = "type";
  static final Integer TYPE_LEGACY_TOTP = new Integer(-1); // TODO: remove April 2010

  private Hashtable data;
  
  public Account() {
    data = new Hashtable(6);
  }
  
  public String getEmail() {
    return (String) data.get(EMAIL_COLUMN);
  }

  public String getSecret() {
    return (String) data.get(SECRET_COLUMN);
  }
  
  public int getCounter() {
    Integer counter = (Integer) data.get(COUNTER_COLUMN);
    if (counter == null) {
      return 0;
    }
    return counter.intValue();
  }
  
  public void setEmail(String emailAddress) {
    data.put(EMAIL_COLUMN, emailAddress);
  }
  
  public void setCounter(int counter) {
    data.put(COUNTER_COLUMN, new Integer(counter));
  }
  
  public void setSecret(String secret) {
    data.put(SECRET_COLUMN, secret);
  }
  
  public void setType(AccountDb.OtpType type) {
    data.put(TYPE_COLUMN, type.value);
  }
  
  public AccountDb.OtpType getType() {
    Integer type = (Integer) data.get(TYPE_COLUMN);
    if (type != null) {
      return AccountDb.OtpType.getEnum(type.intValue());
    }
    return null;
  }

  public int getUID() {
    return getEmail().hashCode();
  }

  
}
